package cn.juque.datapipeline.api.enums;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.juque.common.exception.AppException;

import java.util.Date;

/**
 * @author nuoka
 * @version 1.0.0
 * <li></li>
 * @date 2022/7/21 15:47
 **/
public enum FieldExpressionEnum {

    /**
     * enum
     */
    UUID,
    CURRENT_DATE_YYYY_MM_DD,
    CURRENT_DATE_YYYYMMDD,
    CURRENT_DATE_YYYY_MM_DD_HH_MM_SS,
    ;

    FieldExpressionEnum() {
    }

    public static String getValue(FieldExpressionEnum expression) {
        switch (expression) {
            case UUID:
                return IdUtil.simpleUUID();
            case CURRENT_DATE_YYYYMMDD:
                return DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN);
            case CURRENT_DATE_YYYY_MM_DD:
                return DateUtil.format(new Date(), DatePattern.NORM_DATE_PATTERN);
            case CURRENT_DATE_YYYY_MM_DD_HH_MM_SS:
                return DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN);
            default:
                throw new AppException(DataPipelineMsgEnum.FILE_PROPERTIES_WRONG.getCode(),
                    "表达式【" + expression.name() + "】配置错误");
        }
    }
}
